package com.bj58.ecdata.dashboard.databll;

import java.util.Collection;
import java.util.List;

import com.bj58.ecdata.dashboard.cache.ServiceBeanFactory;
import com.bj58.ecdata.dashboard.dbentity.NetFlow_AB_Test;
import com.bj58.ecdata.dashboard.dbentity.NetFlow_Special;
import com.bj58.ecdata.dashboard.dbentity.NetFlow_URL;
import com.bj58.ecdata.dashboard.service.AbstractBaseService;
import com.bj58.ecdata.dashboard.utils.NetFlowABTestUitls;
import com.bj58.ecdata.dashboard.utils.ReflectUtil;
import com.google.common.collect.Lists;

public class RealTimeABTestBLL {
	private static AbstractBaseService<NetFlow_AB_Test> abTestService =ServiceBeanFactory.get(NetFlow_AB_Test.class,null);
	private static AbstractBaseService<NetFlow_Special> specialService =ServiceBeanFactory.get(NetFlow_Special.class,null);
	private static AbstractBaseService<NetFlow_URL> urlService =ServiceBeanFactory.get(NetFlow_URL.class,null);

	 /** 
	  * 实时AB测数据, 累加数据
	 * @throws IllegalAccessException 
	 * @throws InstantiationException 
	 */
	public static List<Object> getDaySumData(String businessName, String platfrom, String pageType, String indexType,String identity,String stat_date) throws Exception{
		String CON = "stat_date='%s' AND biz='%s' AND platform='%s' AND pagetype='%s' AND company='58' AND identify='%s'";
		String cols = "stat_hour, stat_min, "+indexType;
		String condition = String.format(CON, stat_date,businessName,platfrom, pageType,identity);
		
		List<NetFlow_AB_Test> list = abTestService.getListByConditon(cols, condition, "stat_hour, stat_min");
		Collection<NetFlow_AB_Test>  tmpCollection = NetFlowABTestUitls.exchange(list,NetFlow_AB_Test.class);
//		System.err.println(tmpCollection.size());
		List<Object> rsList = Lists.newArrayList();
		for(NetFlow_AB_Test vo : tmpCollection){
			Object val = ReflectUtil.getVal(vo, indexType);
			rsList.add(val == null ? 0 : val);
		}
		
		return rsList;
	}
	
	 /** 
	  * 实时Special测数据, 累加数据
	 * @throws IllegalAccessException 
	 * @throws InstantiationException 
	 */
	public static List<Object> getSpecialDaySumData(String businessName, String platfrom, String pageType, String indexType,String identity,String stat_date) throws Exception{
		String CON = "stat_date='%s' AND biz='%s' AND platform='%s' AND pagetype='%s' AND company='58' AND identify='%s'";
		String cols = "stat_hour, stat_min, "+indexType;
		String condition = String.format(CON, stat_date,businessName,platfrom, pageType,identity);
		
		List<NetFlow_Special> list = specialService.getListByConditon(cols, condition, "stat_hour, stat_min");
		Collection<NetFlow_Special>  tmpCollection = NetFlowABTestUitls.exchange(list, NetFlow_Special.class);
		List<Object> rsList = Lists.newArrayList();
		for(NetFlow_Special vo : tmpCollection){
			Object val = ReflectUtil.getVal(vo, indexType);
			rsList.add(val == null ? 0 : val);
		}
		
		return rsList;
	}

	 /** 
	  * 实时url测数据, 累加数据
	 * @throws IllegalAccessException 
	 * @throws InstantiationException 
	 */
	public static List<Object> getURLDaySumData(String businessName, String platfrom, String pageType, String indexType,String identity,String stat_date) throws Exception{
		String CON = "stat_date='%s' AND biz='%s' AND platform='%s' AND pagetype='%s' AND company='58' AND identify='%s'";
		String cols = "stat_hour, stat_min, "+indexType;
		String condition = String.format(CON, stat_date,businessName,platfrom, pageType,identity);
		
		List<NetFlow_URL> list = urlService.getListByConditon(cols, condition, "stat_hour, stat_min");

		Collection<NetFlow_URL>  tmpCollection = NetFlowABTestUitls.exchange(list, NetFlow_URL.class);
		List<Object> rsList = Lists.newArrayList();
		for(NetFlow_URL vo : tmpCollection){
			Object val = ReflectUtil.getVal(vo, indexType);
			rsList.add(val == null ? 0 : val);
		}
		
		return rsList;
	}
	
}
